/**
 * 
 */
package com.cea.papyrus.core.presentation.providers;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.uml2.uml.LiteralUnlimitedNatural;
import org.eclipse.uml2.uml.MultiplicityElement;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.edit.providers.MultiplicityElementItemProvider;

/**
 * Extension of the class MultiplicityElementItemProvider
 * Major reason = overrides visibility of static method...
 */
public class ExtendedMultiplicityElementItemProvider extends
		MultiplicityElementItemProvider {

	public ExtendedMultiplicityElementItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}
	
	/**
	 * Duplicate code from {@link MultiplicityElementItemProvider#appendMultiplicity(StringBuffer, Object)} for visibility
	 * @see {@link MultiplicityElementItemProvider#appendMultiplicity(StringBuffer, Object)}
	 */
	protected static StringBuffer appendMultiplicity(StringBuffer text,
			Object object) {

		if (object instanceof MultiplicityElement) {
			MultiplicityElement multiplicityElement = (MultiplicityElement) object;

			if (multiplicityElement
				.eIsSet(UMLPackage.Literals.MULTIPLICITY_ELEMENT__LOWER)
				|| multiplicityElement
					.eIsSet(UMLPackage.Literals.MULTIPLICITY_ELEMENT__UPPER)) {

				if (text.length() > 0) {
					text.append(' ');
				}

				int upper = multiplicityElement.getUpper();

				text
					.append('[')
					.append(multiplicityElement.getLower())
					.append("..").append(upper == LiteralUnlimitedNatural.UNLIMITED ? "*" : String.valueOf(upper)).append(']'); //$NON-NLS-1$ //$NON-NLS-2$
			}
		}

		return text;
	}

}
